package com.inwavetech.os.sync.jsonparser;

import com.inwavetech.os.util.SyncDateFormat;

import java.text.ParseException;

/**
 * Created by jgskin on 3/6/14.
 */
public class DateCleaner implements JsonCleaner {
    private final SyncDateFormat syncDateFormat;
    private boolean required;

    public DateCleaner(SyncDateFormat syncDateFormat, boolean required) {
        this.syncDateFormat = syncDateFormat;
        this.required = required;
    }

    @Override
    public Object validateAndClean(String receivedValue) {
        if (receivedValue.isEmpty() && required == false) {
            return null;
        }

        try {
            return syncDateFormat.parse(receivedValue);
        } catch (ParseException e) {
            return false;
        }
    }
}
